package com.example.demo.controller;

import com.example.demo.model.User;
import com.example.demo.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class RegisterController {
    @Autowired
    private RegisterService registerService;

    @RequestMapping("save")
    public String save(User user, ModelMap modelMap){
        try {
            registerService.save(user);
        }catch (Exception e){
            e.printStackTrace();
            modelMap.put("error",e);
            return "error";
        }
        return "redirect:/login";
    }
}
